package com.xxgc.qinglian.qinglianserver.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xxgc.qinglian.qinglianserver.entity.CountdownEntity;
import com.xxgc.qinglian.qinglianserver.entity.CountdownEntityRepository;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/countdown")
@Tag(name = "倒计时接口")
public class CountdownController {

    @Autowired
    private CountdownEntityRepository countdownEntityRepository;

    //    需要一个保存倒计时的接口
    @PostMapping("/save")
    public boolean save(@RequestBody Map<String, Object> map) {
        CountdownEntity countdown = new CountdownEntity();
        countdown.setId(1);
        countdown.setDays(Integer.parseInt(map.get("days").toString()));
        countdown.setHours(Integer.parseInt(map.get("hours").toString()));
        countdown.setMinutes(Integer.parseInt(map.get("minutes").toString()));
        countdown.setSeconds(Integer.parseInt(map.get("seconds").toString()));
        return countdownEntityRepository.save(countdown);
    }
    //    一个获取倒计时的接口
    @GetMapping("/get")
    public CountdownEntity get(){
        QueryWrapper<CountdownEntity> qw = new QueryWrapper<>();
        qw.eq("id", 1);
        return countdownEntityRepository.getOne(qw);
    }
    //    一个删除倒计时的接口
    @DeleteMapping("/delete")
    public boolean delete(){
        QueryWrapper<CountdownEntity> qw = new QueryWrapper<>();
        qw.eq("id", 1);
        return countdownEntityRepository.remove(qw);
    }
}
